home *** CD-ROM | disk | FTP | other *** search
- Controlling the REALbasic IDE Through RBScript
-
- Introduction
- In REALbasic 2005R5 or later, you can automate certain tasks in the
- IDE by writing and executing RBScript code. Possible applications
- include automating the build process, analyzing source code, and
- inserting or modifying source text.
-
- To get started, use the "New IDE Script" command under the File menu.
- This presents a simple script editor. Try the following script:
-
- Dim i As Integer
- For i = 3 DownTo 1
- Print str(i) + "..."
- Next
- Print "Lift-off!"
-
- Click the Run button, and you should see a MsgBox appear with the
- contents of each Print command.
-
- Of course this is a useless example. Here's a more useful one, which
- sets the ShortVersion to "1.0J", sets the build language to Japanese,
- and then builds a Mac version of the application:
-
- PropertyValue("App.ShortVersion") = "1.0J"
- BuildWin32 = False
- BuildMacMachO = True
- BuildLanguage = "Japanese"
- DoCommand "BuildApp"
-
- You may be wondering how to know all the magic words, like
- "BuildMacMachO" in the example above. There are two sources for that
- knowledge: one is the reference material at the end of this document.
- The other is to simply record yourself doing the task manually.
-
-
- Recording
- When you click the Record button in a script editor, the editor goes
- into "recording" mode (and the button stays down as long as it's in
- this mode). While recording, any scriptable action you do in the IDE
- is added to the editor as RBScript code. You then return to the
- script editor, stop the recording (by clicking Record again), and
- neaten up the script -- deleting unimportant commands, changing
- constants to variables as required, and so on. The example above was
- made in exactly this way.
-
- Script recording is a powerful feature for automating repetitive
- tasks; it does most of the work for you, freeing you from having to
- know the syntax for most actions.
-
-
- Command-Line Interface
- IDE Scripts can run command-line tools via the DoShellCommand,
- documented below. In addition, there is a command-line tool which
- can drive the IDE via IDE scripts. This is called "rbidescript" and
- is provided and documented separately.
-
-
- Script Functionality - Overview
- Your scripts have access to all the standard functions in RBScript,
- including string manipulation, math, and so on. See the RBScript
- entry in the language reference for a detailed list. Note that the
- standard Print command displays a message box, and the Input command
- gets input via a simple modal dialog. As in any RBScript, you can
- also write methods, classes, or modules within your script if needed
- to help organize your code (though many scripts will be so simple as
- to not need them).
-
- In addition to the standard RBScript functions, there are additional
- functions and properties which are defined just for IDE scripts,
- which manipulate projects in the IDE in various ways. These
- functions are detailed below. Most of them operate on the frontmost
- project window, and on the current project item or method within that
- window. However, there are ways to change the current window or
- location for cases where your script needs to act upon a particular
- item.
-
- Most of the things your script can do fall into one of the following
- categories:
- - Changing the context (SelectWindow, Location)
- - Changing project item properties (PropertyValue)
- - Changing build settings (BuildLanguage, BuildLinux, etc.)
- - Executing commands, as if chosen from a toolbar or menu (DoCommand)
- - Interacting with the user (Print, Input, Beep, Speak)
- - Inspecting or changing source code (Text, SelText, SelStart, SelLength)
-
- There are also a few utility functions that don't fit neatly into the
- above categories (e.g., Clipboard). A complete reference follows.
-
-
- Script Functionality - Reference
-
- Beep: plays the system beep.
-
- BuildLanguage as String: gets or sets the current build language.
-
- BuildLinux as Boolean: gets or sets whether the project builds for Linux.
-
- BuildMacClassics Boolean: gets or sets whether to build a classic Mac app.
-
- BuildMacMachO as Boolean: gets or sets whether to build a Mach-O Mac app.
-
- BuildMacPEF as Boolean: gets or sets whether to build a carbon PEF app.
-
- BuildRegion as String: gets or sets the region code to be used in built apps.
-
- BuildWin32 as Boolean: gets or sets whether to build a Windows app.
-
- Clipboard as String: gets or sets the content of the copy/paste buffer.
-
- DoCommand( cmdName as String ): Executes a command, as if the user
- had pressed the corresponding toolbar button or selected a menu item.
- Every such command in the IDE has a unique name which is used as the
- argument for DoCommand. To find the name of a particular command,
- use the script recording feature.
-
- DoShellCommand( cmd as String, timeOut as Integer=3000 ) as String:
- Executes a shell command. The shell environment is set up with the
- following variables: IDE_PATH to point to the directory containing
- the IDE; PROJECT_PATH to point to the directory containing the
- project in the frontmost window; and PROJECT_FILE to point to the
- actual project file. The command is executed in synchronous
- (blocking) mode, and returns any output as the result.
-
- EndOfLine as String: returns the default line ending for the platform
- you're running on. This is also the line separator used in source
- code text (e.g. that returned by Text and SelText).
-
- Location as String: gets or sets the current location in the project,
- as shown in the Location item of the main toolbar. A script can use
- this both to see its current context, and to navigate to some other
- part of the project.
-
- OpenFile( path as String ): attempts to open a REALbasic document
- (e.g. project file) at the given path, which may be either a native
- or a shell path.
-
- ProjectItem as String: returns the name of the current project item,
- i.e. the project item that is currently being edited, or that is
- selected in the Project tab.
-
- PropertyValue( propName as String ) as String: gets or sets the value
- of a project itme property. The propName argument may be just the
- property name, in which case the property is found on the current
- project item; or it may be the name of a project item plus the
- property name, separated by a dot. You may also use the special
- keyword "App" to refer to the blessed Application subclass, even if
- that is not actually named App. The following are all valid property
- references: "Width", "Window1.Width", "App.MajorVersion".
-
- RunStript( scriptName as String ): Runs a script with the given name,
- found in the Scripts folder (either next to the IDE or next to the
- frontmost project file). Note that due to a bug in RBScript, this
- may currently crash the IDE. We hope to have that fixed soon.
-
- SelectWindow( windowTitle as String ): Brings a window to the front,
- specified by its title. If there is more than one window with the
- given title, the one closest to the front is the one activated.
-
- SelectWindow( index as Integer ): Brings a window to the front by its
- current index in the Window list (see the WindowCount and WindowTitle
- functions).
-
- SelLength as Integer: gets or sets the length (in characters) of the
- current selection in the current code editor, if any.
-
- SelStart as Integer: gets or sets the offset of the selection (or
- insertion point) in the current code editor.
-
- SelText as String: gets or sets the selected text in the current code
- editor. Note that after assigning to SelText, the selection will be
- empty and positioned right after the inserted text. (This is the
- same behavior as EditField.SelText.)
-
- Speak( text as String, interrupt as Boolean=False ): Speaks the given
- text via the system speech synthesis engine. If interrupt = True,
- then it interrupts any previous speech; otherwise it waits for
- previous speech to finish. This is the same behavior as the built-in
- Speak command in REALbasic.
-
- Sublocations( baseLocation as String ): Returns all the locations
- within the given base location, as a space-delimited string. For
- example, if baseLocation is "App", then this might return
- "App.Activate App.CancelClose App.Close" (and so on). The set of
- locations returned should be the same ones suggested by
- autocompletion in the Location field within the IDE. If baseLocation
- is an empty string, then this returns the set of project items in the
- frontmost project.
-
- Text as String: gets or sets the entire text of the current code editor.
-
- WindowCount as Integer: returns the number of windows in the IDE.
-
- WindowTitle( index as Integer ) as String: returns the title of a
- window indicated by its current index in the window list. An index
- of 0 means the frontmost window.
-